<template>
  <div>
    <el-dialog
        :title="!dataForm.id ? $t('handle.add') : $t('handle.update')"
        :close-on-click-modal="false"
        :visible.sync="visible">
    <div v-loading = loading>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">
      <!-- <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="所属小区" >
              <el-cascader style="width: 100%;" ref="housing" v-model="housEasteAddress" :options="housEasteOptions" @click.native="getOne" @active-item-change="getHousEaste" :props="housEasteProps"></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属楼栋" >
              <el-form-item >
                  <el-cascader style="width: 100%;" ref="building" v-model="buildingAddress" :options="buildingOptions" @click.native="getCountry" @active-item-change="getbuilding" :props="buildingProps"></el-cascader>
              </el-form-item>
          </el-form-item>
        </el-col>
      </el-row> -->
      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="标准地址" prop="dgStandardInfoId">
            <el-input v-model="dataForm.addressText" placeholder="标准地址" :disabled="true" style="width:90%"></el-input><el-button style="width:10%" type="info" :disabled="false" plain @click="addressDialogOpen()">选择</el-button>
          </el-form-item>
        </el-col>
      </el-row>
       <el-row :gutter="24">
            <el-col :span="12">
                <el-form-item label="设备名称" prop="name">
                    <el-input v-model="dataForm.name" placeholder="设备名称"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="设备编号" prop="number">
                    <el-input v-model="dataForm.number" placeholder="设备编号"></el-input>
                </el-form-item>
            </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="产品代码" prop="productCode">
                <el-input v-model="dataForm.productCode" placeholder="设备产品代码"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="设备状态" prop="status">
                <el-select style="width: 100%;" v-model="dataForm.status" filterable placeholder="请选择">
                    <el-option v-for="item in dicts" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="安装地址" prop="installationAddress">
                    <el-input v-model="dataForm.installationAddress" placeholder="设备安装地址"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
                <el-form-item label="IP地址" prop="ip">
                    <el-input v-model="dataForm.ip" placeholder="ip"></el-input>
                </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="调用类型" prop="callMethod">
                <el-select style="width: 100%;" v-model="dataForm.callMethod" filterable placeholder="请选择">
                    <el-option v-for="item in deviceDataDicts" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="内部代理域名" prop="innerProxyServer">
                <el-input v-model="dataForm.innerProxyServer" placeholder="内部代理域名"></el-input>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="硬盘IP地址" prop="hardiskIp">
                    <el-input v-model="dataForm.hardiskIp" placeholder="硬盘ip地址"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
                <el-form-item label="通道id" prop="channelId">
                    <el-input v-model="dataForm.channelId" placeholder="通道id"></el-input>
                </el-form-item>
          </el-col>
      </el-row>
       <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="设备类型" prop="deviceType">
                 <el-select style="width: 100%;" v-model="dataForm.deviceType" filterable placeholder="请选择"  @change="disableStstus">
                    <el-option v-for="item in deviceTypeDicts" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="设备用途" prop="purpose">
               <el-select style="width: 100%;" v-model="dataForm.purpose" filterable placeholder="请选择">
                    <el-option v-for="item in purposeDicts" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="品牌" prop="brand">
                    <el-input v-model="dataForm.brand" placeholder="品牌"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
                <el-form-item label="型号" prop="model">
                    <el-input v-model="dataForm.model" placeholder="型号"></el-input>
                </el-form-item>
          </el-col>
      </el-row>
       <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="管理用户" prop="managerUsername">
                    <el-input v-model="dataForm.managerUsername" placeholder="管理用户名"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
                <el-form-item label="管理密码" prop="managerPassword">
                    <el-input v-model="dataForm.managerPassword" placeholder="管理密码"></el-input>
                </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="负责人" prop="chargePerson">
                    <el-input v-model="dataForm.chargePerson" placeholder="负责人"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="12">
                <el-form-item :label="$t('form.contactWay')" prop="chargePersonPhone">
                    <el-input v-model="dataForm.chargePersonPhone" placeholder="负责人联系方式"></el-input>
                </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
              <el-form-item label="接入方式" prop="accessType">
                <el-select style="width: 100%;" v-model="dataForm.accessType" filterable placeholder="请选择">
                    <el-option v-for="item in accessTypeDicts" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支持协议" prop="supportAgreement">
              <el-select style="width: 100%;" v-model="dataForm.supportAgreement" filterable placeholder="请选择">
                <el-option v-for="item in supportAgreementDicts" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="连接时间" prop="connectData">
                <el-date-picker
                    v-model="dataForm.connectData"
                    type="datetime"
                    placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;">
                </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="搭建时间" prop="deviceCreateDate">
                <el-date-picker
                    v-model="dataForm.deviceCreateDate"
                    type="datetime"
                    placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;">
                </el-date-picker>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="坐标经度" prop="longitude">
            <el-input v-model="dataForm.longitude" :disabled="false" placeholder="坐标经度"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="坐标纬度" prop="latitude">
            <el-input v-model="dataForm.latitude" :disabled="false" placeholder="坐标纬度"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="showDeviceMoveData" :gutter="24">
        <el-col :span="12">
           <el-form-item label="移动前网格" prop="beforeMovingGrid">
            <el-input v-model="dataForm.beforeMovingGridName"  placeholder="移动前网格" :disabled="true" style="width:80%"></el-input><el-button style="width:20%" type="info" :disabled="false" plain @click="griddingDialogOpen()">选择</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="12">
           <el-form-item label="移动后网格" prop="afterMovingGrid">
            <el-input v-model="dataForm.afterMovingGridName"  placeholder="移动后网格" :disabled="true" style="width:80%"></el-input><el-button style="width:20%" type="info" :disabled="false" plain @click="griddingDialogOpen1()">选择</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="showDeviceMoveData" :gutter="24">
        <el-col :span="12">
          <el-form-item label="移动前经度" prop="beforeMovingLongitude">
            <el-input v-model="dataForm.beforeMovingLongitude" :disabled="false" placeholder="移动前经度"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="移动前纬度" prop="beforeMovingLatitude">
            <el-input v-model="dataForm.beforeMovingLatitude" :disabled="false" placeholder="移动前纬度"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
       <el-row v-if="showDeviceMoveData" :gutter="24">
        <el-col :span="12">
          <el-form-item label="移动后经度" prop="afterMovingLongitude">
            <el-input v-model="dataForm.afterMovingLongitude" :disabled="false" placeholder="移动后经度"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="移动后纬度" prop="afterMovingLatitude">
            <el-input v-model="dataForm.afterMovingLatitude" :disabled="false" placeholder="移动后纬度"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="移动时间" prop="moveDate">
                <el-date-picker
                    v-model="dataForm.moveDate"
                    type="datetime"
                    placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;">
                </el-date-picker>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row v-if ="isAuth('ic:device:mqttCreate') ">
        <el-col :span="24">
          <el-form-item label="mqtt用户连接密码" prop="mqttPwd">
            <el-input v-model="dataForm.mqttPwd" :disabled="false" placeholder="新增时不用填写自动读取配置参数"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="24">
          <el-col :span="24">
            <gdMap :dataForm="dataForm" ref="gdMap" :regionAllName ="regionAllName"></gdMap>
          </el-col>
      </el-row>

    <div style="text-align:right;margin-top: 70px;">
    <span slot="footer" class="dialog-footer">
      <el-button @click="callOf()">{{ $t('handle.cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('handle.confirm') }}</el-button>
    </span>
    </div>
    </div>
  </el-dialog>
  <address-Dialog v-if="addressVisible" ref="addressDialog" @receiveParameters="getAddressParameters"></address-Dialog>
  <grid-Dialog v-if="gridVisible" ref="gridDialog" @receiveParameters="getGridParameters"></grid-Dialog>
  <grid-Dialog1 v-if="gridVisible1" ref="gridDialog1" @receiveParameters="getGridParameters1"></grid-Dialog1>
  </div>
</template>
<script>
import AddressDialog from "./addressDialog";
import GridDialog from "./griddingDialog";
import gdMap from "./dialog/gdMap";
import { isIp } from "@/utils/validate";
export default {
  data() {
    let checkCIp = (rule, value, callback) => {
      if (value !== "") {
        if (isIp(value)) {
          callback();
        } else {
          callback(new Error("IP格式不正确"));
        }
      } else {
        callback(new Error("IP不能为空"));
      }
    };
    let checkCIp1 = (rule, value, callback) => {
      if (value.length >0) {
        if (isIp(value)) {
          callback();
        } else {
          callback(new Error("IP格式不正确"));
        }
      } else {
        callback();
      }
    };
    return {
      gridVisible:false,
      gridVisible1:false,
      showDeviceMoveData:false,
      superAdmin: sessionStorage.getItem("superAdmin"),
      deviceId: "",
      loading: false,
      communityId: "",
      addressVisible: false,
      supportAgreementDicts: [],
      deviceDataDicts: [],
      accessTypeDicts: [],
      dicts: [],
      deviceTypeDicts: [],
      purposeDicts: [],
      visible: false,
      dataForm: {
        id: "",
        name: "",
        number: "",
        productCode: "",
        installationAddress: "",
        ip: "",
        hardiskIp: "",
        channelId: "",
        bulidingId: "",
        housingEstateId: "",
        deviceType: "",
        purpose: "",
        status: "",
        connectData: "",
        deviceCreateDate: "",
        dgStandardInfoId: "",
        delFlag: "",
        brand: "",
        model: "",
        managerUsername: "",
        managerPassword: "",
        chargePerson: "",
        chargePersonPhone: "",
        accessType: "",
        supportAgreement: "",
        callMethod: "",
        addressText: "",
        longitude: "",
        latitude: "",
        regionAllName: this.regionAllName,
        mqttPwd:"",
        innerProxyServer:"",
        beforeMovingGrid:"",
        beforeMovingGridName:"",
        afterMovingGrid:"",
        afterMovingGridName:"",
        beforeMovingLongitude:"",
        beforeMovingLatitude:"",
        afterMovingLongitude:"",
        afterMovingLatitude:"",
        moveDate:"",
      },
      buildingAddress: [],
      buildingOptions: [],
      buildingProps: {
        value: "id",
        label: "name",
        children: "children"
      },
      housEasteAddress: [],
      housEasteOptions: [],
      housEasteProps: {
        value: "id",
        label: "name",
        children: "children"
      },
      dataRule: {
        housingEstateId: [
          { required: false, message: "请选择所属小区", trigger: "change" }
        ],
        buildingId: [
          { required: false, message: "请选择所属楼栋", trigger: "change" }
        ],
        name: [
          { required: true, message: "设备名称不能为空", trigger: "blur" }
        ],
        number: [
          { required: true, message: "设备编码不能为空", trigger: "blur" }
        ],
        productCode: [
          { required: true, message: "产品代码不能为空", trigger: "blur" }
        ],
        installationAddress: [
          { required: true, message: "安装地址不能为空", trigger: "blur" }
        ],
        ip: [{ required: true, validator: checkCIp, trigger: "blur" }],
        hardiskIp: [{ validator: checkCIp1, trigger: "blur" }],
        deviceType: [
          { required: false, message: "设备类型不能为空", trigger: "blur" }
        ],
        purpose: [
          { required: false, message: "设备用途不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "设备状态不能为空", trigger: "change" }
        ],
        connectData: [
          { required: true, message: "请选择连接时间", trigger: "change" }
        ],
        deviceCreateDate: [
          { required: true, message: "请选择搭建时间", trigger: "change" }
        ]
        // dgStandardInfoId: [
        //   {
        //     required: true,
        //     message: "设备所在地理位置不能为空",
        //     trigger: "blur"
        //   }
        // ]
      }
    };
  },
  /*弹窗就会执行的函数 */
  mounted: function() {
    // this.getCountry()
    // this.getOne()
  },
  components: {
    "address-Dialog": AddressDialog,
    gdMap: gdMap,
     "grid-Dialog": GridDialog,
    "grid-Dialog1": GridDialog
  },
  computed: {
    addressId() {
      return this.$store.state.address.regionId;
    },
    regionAllName() {
      return (
        (this.$store.state.address.regionPnames
          ? this.$store.state.address.regionPnames + ","
          : "") + this.$store.state.address.regionName
      );
    }
  },
  methods: {
    disableStstus(val) {
      if (val === "5") {
       this.showDeviceMoveData = true
      }else{
        this.showDeviceMoveData = false
      }
    },
    griddingDialogOpen() {
      this.gridVisible = true;
      this.$nextTick(() => {
        this.$refs.gridDialog.init();
      });
    },
    griddingDialogOpen1() {
      this.gridVisible1 = true;
      this.$nextTick(() => {
        this.$refs.gridDialog1.init();
      });
    },
    // 实有单位弹框返回数据接收
    getAddressParameters(data) {
      this.dataForm.dgStandardInfoId = data.selectId;
      this.dataForm.addressText = data.selectText;
    },
    getGridParameters(data){
      this.dataForm.beforeMovingGrid = data.selectId;
      this.dataForm.beforeMovingGridName = data.selectText;
    },
    getGridParameters1(data){
      this.dataForm.afterMovingGrid = data.selectId;
      this.dataForm.afterMovingGridName = data.selectText;
    },
    // 显示选择地址组件
    addressDialogOpen() {
      this.addressVisible = true;
      this.$nextTick(() => {
        this.$refs.addressDialog.init();
      });
    },
    clearForm() {
      this.dataForm.name = "";
      this.dataForm.number = "";
      this.dataForm.productCode = "";
      this.dataForm.installationAddress = "";
      this.dataForm.ip = "";
      this.dataForm.hardiskIp = "";
      this.dataForm.channelId = "";
      this.dataForm.brand = "";
      this.dataForm.model = "";
      this.dataForm.managerUsername = "";
      this.dataForm.managerPassword = "";
      this.dataForm.chargePerson = "";
      this.dataForm.chargePersonPhone = "";
      this.dataForm.accessType = "";
      this.dataForm.supportAgreement = "";
      this.dataForm.callMethod = "";
      this.dataForm.longitude = "";
      this.dataForm.latitude = "";
      this.dataForm.innerProxyServer = "";
      this.dataForm.beforeMovingGrid="";
      this.dataForm.beforeMovingGridName="";
      this.afterMovingGrid="";
      this.afterMovingGridName="";
      this.beforeMovingLongitude="";
      this.beforeMovingLatitude="";
      this.afterMovingLongitude="";
      this.afterMovingLatitude="";
    },
    init(
      id,
      dicts,
      deviceTypeDicts,
      purposeDicts,
      accessTypeDicts,
      supportAgreementDicts,
      deviceDataDicts,
      communityId
    ) {
      this.visible = true;
      this.accessTypeDicts = accessTypeDicts;
      this.supportAgreementDicts = supportAgreementDicts;
      this.dicts = dicts;
      this.deviceTypeDicts = deviceTypeDicts;
      this.purposeDicts = purposeDicts;
      this.deviceDataDicts = deviceDataDicts;
      this.dataForm.id = id || 0;
      this.communityId = communityId;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        this.clearForm();
      });
      if (this.dataForm.id) {
        this.$http({
          url: `/dg-ic/ic/device/info/${this.dataForm.id}`,
          method: "get",
          params: this.$http.adornParams()
        }).then(({ data }) => {
          if (data && data.code === 0) {
            if(data.data.deviceType === 5){
              this.showDeviceMoveData = true;
            }
            this.dataForm.name = data.data.name;
            this.dataForm.number = data.data.number;
            this.dataForm.productCode = data.data.productCode;
            this.dataForm.installationAddress = data.data.installationAddress;
            this.dataForm.ip = data.data.ip;
            this.dataForm.regionId = data.data.regionId;
            this.dataForm.hardiskIp = data.data.hardiskIp;
            this.dataForm.channelId = data.data.channelId;
            (this.dataForm.brand = data.data.brand),
              (this.dataForm.model = data.data.model),
              (this.dataForm.managerUsername = data.data.managerUsername),
              (this.dataForm.managerPassword = data.data.managerPassword),
              (this.dataForm.chargePerson = data.data.chargePerson),
              (this.dataForm.chargePersonPhone = data.data.chargePersonPhone),
              (this.dataForm.accessType = String(data.data.accessType)),
              (this.dataForm.callMethod = String(data.data.callMethod)),
              (this.dataForm.supportAgreement = String(
                data.data.supportAgreement
              )),
              (this.dataForm.longitude = data.data.longitude),
              (this.dataForm.latitude = data.data.latitude),
              // this.dataForm.bulidingId = data.data.bulidingId

              // this.dataForm.housingEstateId = data.data.housingEstateId
              (this.housEasteOptions = [
                {
                  id: data.data.housingEstateId,
                  name: data.data.housingName
                }
              ]);
            this.housEasteAddress = [data.data.housingEstateId];
            this.buildingOptions = [
              {
                id: data.data.bulidingId,
                name: data.data.buildingName
              }
            ];
            this.buildingAddress = [data.data.bulidingId];
            this.dataForm.purpose = String(data.data.purpose);
            this.dataForm.deviceType = String(data.data.deviceType);
            this.dataForm.status = String(data.data.status);
            this.dataForm.connectData = data.data.connectData;
            this.dataForm.deviceCreateDate = data.data.deviceCreateDate;
            this.dataForm.dgStandardInfoId = data.data.dgStandardInfoId;
            this.dataForm.delFlag = String(data.data.delFlag);
            this.dataForm.mqttPwd =  data.data.mqttPwd;
            this.dataForm.innerProxyServer = data.data.innerProxyServer;
            this.dataForm.beforeMovingGrid = data.data.beforeMovingGrid;
            this.dataForm.beforeMovingGridName = data.data.beforeMovingGridName;
            this.dataForm.afterMovingGrid = data.data.afterMovingGrid;
            this.dataForm.afterMovingGridName = data.data.afterMovingGridName;
            this.dataForm.beforeMovingLongitude = data.data.beforeMovingLongitude;
            this.dataForm.beforeMovingLatitude = data.data.beforeMovingLatitude;
            this.dataForm.afterMovingLongitude = data.data.afterMovingLongitude;
            this.dataForm.afterMovingLatitude = data.data.afterMovingLatitude;
            this.dataForm.moveDate = data.data.moveDate;

            this.$refs.gdMap.initSearch(
              this.dataForm.longitude,
              this.dataForm.latitude
            );
          }
        });
      } else {
        this.$refs.gdMap.initSearch(null, null);
      }
    },

    dataFormSubmit() {
      this.$refs["dataForm"].validate(validate => {
        if (validate) {
          this.loading = true;
          this.$http({
            url: `/dg-ic/ic/device/${!this.dataForm.id ? "save" : "update"}`,
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              name: this.dataForm.name,
              number: this.dataForm.number,
              productCode: this.dataForm.productCode,
              installationAddress: this.dataForm.installationAddress,
              ip: this.dataForm.ip,
              hardiskIp: this.dataForm.hardiskIp,
              channelId: this.dataForm.channelId,
              bulidingId: this.buildingAddress[this.buildingAddress.length - 1],
              regionId: !this.dataForm.id?this.addressId:this.dataForm.regionId, // 获取的区域id是左侧树获取的
              housingEstateId:
                sessionStorage.getItem("thiscommunityId") === "null"
                  ? this.communityId
                  : sessionStorage.getItem("thiscommunityId"),
              purpose: this.dataForm.purpose,
              deviceType: this.dataForm.deviceType,
              status: this.dataForm.status,
              connectData: this.dataForm.connectData,
              deviceCreateDate: this.dataForm.deviceCreateDate,
              dgStandardInfoId: this.dataForm.dgStandardInfoId,
              brand: this.dataForm.brand,
              model: this.dataForm.model,
              managerUsername: this.dataForm.managerUsername,
              managerPassword: this.dataForm.managerPassword,
              chargePerson: this.dataForm.chargePerson,
              chargePersonPhone: this.dataForm.chargePersonPhone,
              accessType: this.dataForm.accessType,
              supportAgreement: this.dataForm.supportAgreement,
              callMethod: this.dataForm.callMethod,
              longitude: this.dataForm.longitude,
              latitude: this.dataForm.latitude,
              createBy: this.$store.state.user.id,
              updateBy: this.$store.state.user.id,
              mqttPwd: this.dataForm.mqttPwd,
              innerProxyServer: this.dataForm.innerProxyServer,
              beforeMovingGrid :  this.dataForm.beforeMovingGrid,
              afterMovingGrid : this.dataForm.afterMovingGrid,
              beforeMovingLongitude : this.dataForm.beforeMovingLongitude,
              beforeMovingLatitude : this.dataForm.beforeMovingLatitude,
              afterMovingLongitude :  this.dataForm.afterMovingLongitude,
              afterMovingLatitude :  this.dataForm.afterMovingLatitude,
              moveDate : this.dataForm.moveDate,
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.deviceId = data.data;
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1000,
                onClose: () => {
                  // 如果是新增的话就创建mqtt用户
                  if (!this.dataForm.id) {
                    this.$http({
                      url: "dg-ic/ic/device/permission/createmqtt",
                      method: "post",
                      data: this.$http.adornData({
                        id: this.deviceId
                      })
                    }).then(({ data }) => {
                      if (data && data.code === 0) {
                        this.$message({
                          message: "创建mqtt用户成功",
                          type: "success",
                          duration: 1000,
                          onClose: () => {
                          }
                        });
                      }else{
                        this.$message.console.error(data.msg);
                      }
                    });
                  }

                  this.loading = false;
                  this.visible = false;
                  this.$emit("refreshDataList");
                  this.dataForm.addressText = "";
                  this.$refs[`dataForm`].resetFields();
                  let obj = {};
                  obj.stopPropagation = () => {};
                  this.$refs.housing.clearValue(obj);
                  let obj1 = {};
                  obj1.stopPropagation = () => {};
                  this.$refs.building.clearValue(obj1);
                }
              });
            } else {
              this.$message.console.error(data.msg);
              this.loading = false;
            }
          });
        }
      });
    },
    callOf() {
      this.visible = false;
      this.$nextTick(() => {
        this.dataForm.addressText = "";
        this.$refs["dataForm"].resetFields();
        let obj = {};
        obj.stopPropagation = () => {};
        this.$refs.housing.clearValue(obj);
        let obj1 = {};
        obj1.stopPropagation = () => {};
        this.$refs.building.clearValue(obj1);
      });
    }
  }
};
</script>
